import jsonlines
import os
from elasticsearch import Elasticsearch


es = Elasticsearch("http://localhost:9200")
current_path = "../"
with jsonlines.open(current_path+'/all_news.jsonl', "r") as fp:
    for item in fp:
        doc = {
            'time':item['time'],
            'source':item['source'],
            'category':item['category'],
            'url':item['url'],
            'title':item['title'],
            'content':item['content'],
            'id':item['id'],
        }
        resp = es.index(index="news", document=doc)
        print(resp['result'])